package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.game.GameConfigVo;
import com.qumitech.visualnovel.pubdef.dto.game.GameConfigCopyDTO;
import com.qumitech.visualnovel.service.oldgame.OldGameConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/1/15 10:50
 */

@RestController
@RequestMapping("/api/gameconfig")
public class OldGameConfigController {
    @Autowired
    private OldGameConfigService gameConfigService;

    @RequestMapping(value = "", method = RequestMethod.GET)
    public BaseRsp getGames(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
                            @RequestParam(value = "limit", defaultValue = "10") Integer limit,
                            @RequestParam(name = "game_id", required = false) String gameId,
                            @RequestParam(name = "game_name", required = false) String gameName,
                            @RequestParam(name = "app_version", required = false) String appVersion,
                            @RequestParam(name = "app_channel", required = false) String appChannel) {
        return new BaseRsp(ResultEnum.SUCCESS, gameConfigService.getGames(gameId, gameName, appChannel, appVersion, offset, limit));
    }

    @PutMapping
    public BaseRsp updateGame(@RequestBody GameConfigVo gameConfigVo) {
        gameConfigService.updateGame(gameConfigVo);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @DeleteMapping()
    public BaseRsp removeGame(@RequestParam(name = "game_type", required = false) String gameType,
                              @RequestParam(name = "app_channel") String appChannel,
                              @RequestParam(name = "app_version") String appVersion) {
        gameConfigService.removeGame(gameType, appChannel, appVersion);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping
    public BaseRsp addGame(@RequestBody GameConfigVo gameConfigVo) {
        gameConfigService.addGame(gameConfigVo);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PostMapping("/copy")
    public BaseRsp copyGames(@RequestBody GameConfigCopyDTO gameConfigCopyDTO){
        gameConfigService.copyGame(gameConfigCopyDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @GetMapping("/info")
    public BaseRsp getGameIndexInfo(@RequestParam(name = "app_channel", required = false) String appChannel,
                                    @RequestParam(name = "app_version", required = false) String appVersion){
        return new BaseRsp(ResultEnum.SUCCESS, gameConfigService.getGameIndexInfo(appChannel, appVersion));
    }


    @GetMapping("/baseinfo")
    public BaseRsp getGameBaseInfo(){
        return new BaseRsp(ResultEnum.SUCCESS, gameConfigService.getGameBaseInfo());
    }

}
